#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e6+9;
int t;
int n,m,l,v;
int road[MAXN];
int ans1,ans2;

struct Node{
    int di,vi,ai;
};Node car[MAXN];

void detect1(){
    for(int i=1;i<=n;i++){
        if(car[i].vi>v) ans1++;
    }
    if(ans1==0) ans2=m;
    else ans2=m-1;
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
            ans1=0;
        ans2=0;
        cin>>n>>m>>l>>v;
        for(int j=1;j<=n;j++){
            cin>>car[j].di>>car[j].vi>>car[j].ai;
        }
        for(int j=1;j<=m;j++) cin>>road[j];
        if(car[1].ai==0) detect1();
            //else if(car[1].ai<0) detect2();
                //else detect3();
        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}
